#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "Common.h"
#include "Window.h"
#include "Internals.h"
#include "LCD.h"
#include "Gdi.h"
#include "Assert.h"

GUI_CONTEXT        GUI_Context;        /* Thread wide globals */

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _InitContext
*
* Purpose
*   Initializes the given context.
*
* Special considerations
*   Make sure that no GUI functions are called, because locking is
*   not allowed here (GUITASK_INIT not yet called).
*/
static void _InitContext(GUI_CONTEXT* pContext) {
    /* memset(..,0,..) is not required, as this function is called only at startup of the GUI when data is 0 */
    pContext->pDeviceAPI   = &LCD_APIList; /* &LCD_L0_APIList; */

    pContext->pAFont       = GUI_DEFAULT_FONT;
    pContext->PenSize      = 1;
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
BOOL InitGDI (void)
{
    memset(&GUI_Context, 0, sizeof(GUI_Context));
    /* Init context */
    _InitContext(&GUI_Context);
    
    return 1;
}

void TerminateGDI( void )
{
    return;
}

void GUIDrawRect(int x0, int y0, int x1, int y1)
{
    if(GUI_Context.pDeviceAPI && GUI_Context.pDeviceAPI->pfDrawRect)
    {
        GUI_Context.pDeviceAPI->pfDrawRect(x0, y0, x1, y1);
    }
}

void GUIFillRect(int x0, int y0, int x1, int y1)
{
    if(GUI_Context.pDeviceAPI && GUI_Context.pDeviceAPI->pfFillRect)
    {
        GUI_Context.pDeviceAPI->pfFillRect(x0, y0, x1, y1, PIXEL_ON);
    }
}

void GUIClearRect(int x0, int y0, int x1, int y1) 
{
    if(GUI_Context.pDeviceAPI && GUI_Context.pDeviceAPI->pfFillRect)
    {
        GUI_Context.pDeviceAPI->pfFillRect(x0, y0, x1, y1, PIXEL_OFF);
    }
}
